You are here: Symbol Reference > Dew Namespace > Dew.Math Namespace > Dew.Math.Units Namespace > Classes > Optimization Class > Optimization Methods > Marquardt Method > Optimization.Marquardt Method (TRealFunction, TGradHess, double[], [In] double[], [In] object[], out double, TMtx, out TOptStopReason, [In] TMtxFloatPrecision, int, double, double, double, TStrings)
Dew Math for .NET
ContentsIndexHome
PreviousUpNext
Optimization.Marquardt Method (TRealFunction, TGradHess, double[], [In] double[], [In] object[], out double, TMtx, out TOptStopReason, [In] TMtxFloatPrecision, int, double, double, double, TStrings)

Minimizes the function of several variables by using the Marquardt optimization algorithm.

Syntax
C#
Visual Basic
public static int Marquardt(TRealFunction Fun, TGradHess GradHess, ref double[] Pars, [In] double[] Consts, [In] object[] ObjConst, out double FMin, TMtx IHess, out TOptStopReason StopReason, [In] TMtxFloatPrecision FloatPrecision, int MaxIter, double Tol, double GradTol, double Lambda0, TStrings Verbose);
Parameters 
Description 
TRealFunction Fun 
Real function (must be of TRealFunction type) to be minimized. 
TGradHess GradHess 
The gradient and Hessian procedure (must be of TGradHess type), used for calculating the gradient and Hessian matrix. 
ref double[] Pars 
Stores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position). 
[In] double[] Consts 
Additional Fun constant parameteres (can be/is usually nil). 
[In] object[] ObjConst 
Additional Fun constant parameteres (can be/is usually nil). 
out double FMin 
Returns function value at minimum. 
TMtx IHess 
Returns inverse Hessian matrix. 
out TOptStopReason StopReason 
Returns reason why minimum search stopped (see TOptStopReason). 
[In] TMtxFloatPrecision FloatPrecision 
Specifies the floating point precision to be used by the routine. 
int MaxIter 
Maximum allowed numer of minimum search iterations. 
double Tol 
Desired Pars - minimum position tolerance. 
double GradTol 
Minimum allowed gradient C-Norm. 
double Lambda0 
Initial lambda step, used in Marquardt algorithm. 
TStrings Verbose 
If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring.  

the number of iterations required to reach the solution(minimum) within given tolerance.

Problem: Find the minimum of the "Banana" function by using the Marquardt method. 

Solution:The Banana function is defined by the following equation: 

 

Also, Marquardt method requires the gradient and Hessian matrix of the function. The gradient of the Banana function is: 

 

and the Hessian matrix is : 

 

 

// Objective function private double Banana(TVec x, TVec c, params object[] o) { return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1-x[0],2); } // Analytical gradient and Hessian matrix of the objective function private void BananaGradHess(TRealFunction Fun, TVec Pars, TVec Consts, object[] obj, TVec Grad, TMtx Hess) { double[] Pars = Parameters.PValues1D(0); Grad[0] = -400.0*(Pars[1]-Math387.IntPower(Pars[0],2))*Pars[0] - 2*(1-Pars[0]); Grad[1] = 200.0*(Pars[1]-Math387.IntPower(Pars[0],2)); Hess.Values1D[0] = -400.0*Pars[1]+1200*Math387.IntPower(Pars[0],2)+2; Hess.Values1D[1] = -400.0*Pars[0]; Hess.Values1D[2] = -400.0*Pars[0]; Hess.Values1D[3] = 200.0; } private void Example() { double[2] Pars; double fmin; Matrix iHess = new Matrix(0,0); TOptStopReason StopReason; // initial estimates for x1 and x2 Pars[0] = 0; Pars[1] = 0; int iters = Optimization.Marquardt(Banana,BananaGradHess,Pars, null, null, out fmin, iHess, out StopReason, TMtxFloatPrecision.mvDouble, 1000, 1.0e-8, 1.0e-8, null); // stop if Iters >1000 or Tolerance < 1e-8 }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!